home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / f_threshold.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  3.4 KB  |  129 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <windows.h>
  21. #include <commctrl.h>
  22.  
  23. #include "resource.h"
  24. #include "filter.h"
  25. #include "filters.h"
  26. #include "ScriptInterpreter.h"
  27. #include "ScriptValue.h"
  28. #include "ScriptError.h"
  29.  
  30. extern HINSTANCE g_hInst;
  31.  
  32. extern "C" void asm_threshold_run(
  33.         void *dst,
  34.         unsigned long width,
  35.         unsigned long height,
  36.         unsigned long stride,
  37.         unsigned long threshold
  38.         );
  39.  
  40. ///////////////////////////////////
  41.  
  42. struct MyFilterData {
  43.     LONG threshold;
  44. };
  45.  
  46. int threshold_run(const FilterActivation *fa, const FilterFunctions *ff) {    
  47.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  48.  
  49.     asm_threshold_run(
  50.             fa->src.data,
  51.             fa->src.w,
  52.             fa->src.h,
  53.             fa->src.pitch,
  54.             mfd->threshold
  55.             );
  56.  
  57.     return 0;
  58. }
  59.  
  60. long threshold_param(FilterActivation *fa, const FilterFunctions *ff) {
  61.     fa->dst.offset    = fa->src.offset;
  62.     fa->dst.modulo    = fa->src.modulo;
  63.     fa->dst.pitch    = fa->src.pitch;
  64.     return 0;
  65. }
  66.  
  67. //////////////////
  68.  
  69. static int threshold_config(FilterActivation *fa, const FilterFunctions *ff, HWND hWnd) {
  70.     if (!fa->filter_data) {
  71.         if (!(fa->filter_data = (void *)new MyFilterData)) return 0;
  72.         memset(fa->filter_data, 0, sizeof MyFilterData);
  73.         ((MyFilterData *)fa->filter_data)->threshold = 128;
  74.     }
  75.  
  76.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  77.  
  78.     mfd->threshold = FilterGetSingleValue(hWnd, mfd->threshold, 0, 256, "threshold");
  79.  
  80.     return 0;
  81. }
  82.  
  83. static void threshold_string(const FilterActivation *fa, const FilterFunctions *ff, char *buf) {
  84.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  85.  
  86.     sprintf(buf," (%d%%)", (mfd->threshold*25)/64);
  87. }
  88.  
  89. static void threshold_script_config(IScriptInterpreter *isi, void *lpVoid, CScriptValue *argv, int argc) {
  90.     FilterActivation *fa = (FilterActivation *)lpVoid;
  91.  
  92.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  93.  
  94.     mfd->threshold = argv[0].asInt();
  95. }
  96.  
  97. static ScriptFunctionDef threshold_func_defs[]={
  98.     { (ScriptFunctionPtr)threshold_script_config, "Config", "0i" },
  99.     { NULL },
  100. };
  101.  
  102. static CScriptObject threshold_obj={
  103.     NULL, threshold_func_defs
  104. };
  105.  
  106. static bool threshold_script_line(FilterActivation *fa, const FilterFunctions *ff, char *buf, int buflen) {
  107.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  108.  
  109.     _snprintf(buf, buflen, "Config(%d)", mfd->threshold);
  110.  
  111.     return true;
  112. }
  113.  
  114. FilterDefinition filterDef_threshold={
  115.     0,0,NULL,
  116.     "threshold",
  117.     "Converts an image to black and white by comparing brightness values.\n\n[Assembly optimized]",
  118.     NULL,NULL,
  119.     sizeof(MyFilterData),
  120.     NULL,NULL,
  121.     threshold_run,
  122.     threshold_param,
  123.     threshold_config,
  124.     threshold_string,
  125.     NULL,
  126.     NULL,
  127.     &threshold_obj,
  128.     threshold_script_line,
  129. };